@(simType: String, workerCount: String, jobCount: String, arrivalRate: String, avgLength: String, ec2InstanceSize: String)(implicit request: RequestHeader)

@import helper._
@import helper.twitterBootstrap._

@main(Html("Simulation running"), currentPage="runSim") {

	<!--div id="onError" class="alert-message error">
        <p>
            <strong>Oops!</strong> <span></span>
        </p>
    </div-->
	
	@form(routes.Application.serveJsonFileForGrid(simType, workerCount, jobCount, arrivalRate, avgLength, ec2InstanceSize)) {
	
	<fieldset>
	<legend> Simulation Details: </legend>
	
	<div class="workerCount">
		<div class="control-group">
			<label class="control-label" for="wc"> Worker Count:</label>
			<div class="controls">
				<input type="text" class="input-small" id="wc">
				@if(simType.equalsIgnoreCase("noAutoSize")) {
					<input type='button' class="btn" id="incrementWorkerButton" value="Increment"/><input type='button' class="btn" id="decrementWorkerButton" value="Decrement"/>
			</div>
					}
		</div>
	</div>
	<br/>
	<div class="jobCount">
		<div class="control-group">
			<label class="control-label" for="jc"> Job Count:</label>
			<div class="controls">
				<input type="text" class="input-small" id="jc" value="@jobCount">
			</div>
		</div>
	</div>
	<br/>
	<div class="avgLength">
		<div class="control-group">
			<label class="control-label" for="al"> Average Length: </label>
			<div class="controls">
				<input type="text" class="input-small" id="al" value="@avgLength">
			</div>
		</div>
	</div>
	<br/>
	<div class="arrivalRate"> 
		<div class="control-group">
			<label class="control-label" for="ar"> Arrival Rate:</label>
			<div class="controls">
				<input type="text" class="input-small" id="ar" value="@arrivalRate">
				@if(simType.equalsIgnoreCase("noAutoSize")) {
					<input type="button" class="btn" id="incrementArrivalRateButton" value="Increment"/>
					<input type="button" class="btn" id="decrementArrivalRateButton" value="Decrement"/>
					}
			</div>
		</div>
	</div>
	<br/>
	<div class="submittedWorkCount">
		<div class="control-group">
			<label class="control-label" for="swc">SWC: </label>
			<div class="controls">
				<input type="text" class="input-small" id="swc">
			</div>
		</div>
	</div>
	<br/>
	<div class="workCompletedCount">
		<div class="control-group">
			<label class="control-label" for="wcc"> Work Completed: </label>
			<div class="controls">
				<input type="text" class="input-small" id="wcc">
			</div>
		</div>
	</div>
	<br/>
	<div class="currentTime">
		<div class="control-group">
			<label class="control-label" for="ct">CurrentTime: </label>
			<div class="controls">
				<input type="text" class="input-small" id="ct">
			</div>
		</div>
	</div>
	<br/>
	<div class="result">
		<div class="control-group">
			<label class="control-label" for="result">Simulation Result: </label>
			<div class="controls">
				<textarea class="input-xlarge" id="result" rows="3"></textarea>
			</div>
		</div>
	</div>
	<br/>
	<div class="cost">
		<div class="control-group">
			<label class="control-label" for="cost">Simulation Cost: </label>
			<div class="controls">
				<textarea class="input-xlarge" id="cost" rows="3"></textarea>
			</div>
		</div>
	</div>
	<div class="temp"></div>
	<br/>
	
	<div class="form-actions">
        <!--button type="submit" class="btn-primary" id="stopButton"> Stop Sim</button-->
		
        <input type="submit" class="btn" value="Save Grid as JSON">
     </div>
	
	
	</fieldset>
    
    }
	@form(routes.Application.serveJsonFileForGrid(simType, workerCount, jobCount, arrivalRate, avgLength, ec2InstanceSize) )  {
		
		
		}
		
	<button class="btn primary" id="stopButton"> Stop </button>
	
	
    <script type="text/javascript" charset="utf-8">
    
        $(function() {
            var WS = window['MozWebSocket'] ? MozWebSocket : WebSocket
            
            var sock = new WS("@routes.Application.webSocketCreation().webSocketURL()")
			
            var receiveEvent = function(event) {
                var data = JSON.parse(event.data)
                
                // Handle errors
                if(data.error) {
                    chatSocket.close()
                    $("#onError span").text(data.error)
                    $("#onError").show()
                    return
                } 
				
				//put msg on screen
				if(data.hasOwnProperty("submittedWorkCount")) {
					//$('.submittedWorkCount').text("submittedWorkCount: " + data.submittedWorkCount)
					$('.submittedWorkCount input').val(" " + data.submittedWorkCount)				
				}
				if(data.hasOwnProperty("workCompletedCount")) {
				
					//$('.workCompletedCount').text("workCompletedCount: " + data.workCompletedCount)
					$('.workCompletedCount input').val(" " + data.workCompletedCount)
				}
				if(data.hasOwnProperty("currentTime")) {
					//$('.currentTime').text("currentTime( HH:MM:SS.ss ): " + data.currentTime)
					$('.currentTime input').val(" " + data.currentTime)
				}
				if(data.hasOwnProperty("workerCount")) {
					//$('.workerCount').text("workerCount: " + data.workerCount)
					//$('.workerCount input').val(" " + data.workerCount)
					$("input#wc").val(data.workerCount)
				}
				if(data.hasOwnProperty("cost")) {
					//$('.result').text("Simulation result: " + data.simulationResult)
					//$('.result input').val(" " + data.simulationResult)
					$("textarea#result").val(data.simulationResult);
					//$('.cost').text("Cost: " + data.cost)
					//$('.cost input').val(" " + data.cost)
					$("textarea#cost").val(data.cost);
				}
				
				}
				
			sock.onmessage = receiveEvent
			
			$("#stopButton").click(function() {
                sock.send(JSON.stringify("STOP"))
				$('.temp').text("sock stop innit")
            });     
			
			$("#incrementWorkerButton").click(function() {
                sock.send(JSON.stringify("ADDWORKER"))
				$('.temp').text("added a worker")
            });
			
			$("#decrementWorkerButton").click(function() {
                sock.send(JSON.stringify("REMOVEWORKER"))
				$('.temp').text("removed a worker")
            });
			
			
			$("#incrementArrivalRateButton").click(function() {
                sock.send(JSON.stringify("INCREMENTARRIVALRATE"))
				$('.temp').text("incremented arrival rate")
            });
			
			$("#decrementArrivalRateButton").click(function() {
                sock.send(JSON.stringify("DECREMENTARRIVALRATE"))
				$('.temp').text("decremented arrival rate")
            });
			
				
		})
    
    </script>
	
	
	}